package com.hsl.test.service.impl;

import com.hsl.test.aop.TAutowired;
import com.hsl.test.aop.TService;
import com.hsl.test.aop.TTransactional;
import com.hsl.test.dao.AccountDao;
import com.hsl.test.pojo.AccountPO;
import com.hsl.test.service.TransferService;

/**
 * @author hsl
 * @Data 2021/12/14
 * @Desc
 */
@TService(value = "transferService")
@TTransactional
public class TransferServiceImpl implements TransferService {

    @TAutowired
    private AccountDao accountDao;

    @Override
    public void transfer(String transferFromNo, String transferToNo, int money) throws Exception {
        //查询转出账户金额
        AccountPO out = accountDao.queryAccountByCardNo(transferFromNo);
        //查询转入账户金额
        AccountPO in = accountDao.queryAccountByCardNo(transferToNo);
        out.setMoney(out.getMoney() - money);
        in.setMoney(in.getMoney() + money);
        //更新转出账户
        accountDao.updateAccountByCardNo(in);
        // 模拟异常
        int i = 1 / 0;
        //更新转入账户out
        accountDao.updateAccountByCardNo(out);
    }
}
